# startup-mysql.pm
# Copyright (C) 2006  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

#
# For more information: http://carrierclass.net/
#
use strict; use warnings;

package CCNv2::Provision::startup_mysql;
use base qw(CCNCore::Provision::startup_mysql);

use CCNv2::Provision::Database::db_ser;
use CCNv2::Provision::Database::db_asterisk;

sub dump_database($)
{
    my $self = shift;
    my ($type,$db) = @_;
    
    if($type eq 'px')
    {
        my $k1 = new CCNv2::Provision::Database::db_ser($self->p);
        unlink $k1->dump_file();
        $k1->dump($db) if $k1->database_looksgood($db);
    }
    if($type eq 'cp')
    {
        my $k1 = new CCNv2::Provision::Database::db_asterisk($self->p);
        unlink $k1->dump_file();
        $k1->dump($db) if $k1->database_looksgood($db);
    }
    
    $self->SUPER::dump_database($type);
}

sub restore_database($)
{
    my $self = shift;
    my ($type,$db) = @_;

    if($type eq 'px')
    {
        my $k1 = new CCNv2::Provision::Database::db_ser($self->p);
        $k1->reprovision($db);
    }
    if($type eq 'cp')
    {
        my $k1 = new CCNv2::Provision::Database::db_asterisk($self->p);
        $k1->reprovision($db);
    }
    
}

1;